package robocup.component.infotypes;

import robocup.component.PConf;

/**
 * The PlayerTypesInfo is a collection of heterogeneous player types. These were
 * received one after another, and subsequently added to this info object.
 */
public class PlayerTypesInfo
    extends Info {

  /**
   * The received player-types.
   */
  public PConf playerTypes[];

  /**
   * The amount of already received player-types.
   */
  private int  filled = 0;

  /**
   * Constructor, sets the infoType to TYPE_PTYPE! Contains all heterogeneous
   * playerType-data, that are defined within the server and sent to the agents.
   */
  public PlayerTypesInfo() {

    super(-1);
    this.infoType = Info.TYPE_PTYPE;
  }

  /**
   * Sets the number of playertypes
   * 
   * @param noOfTypes
   */
  public void setNoOfPlayerTypes(final int noOfTypes) {

    this.playerTypes = new PConf[noOfTypes];
  }

  /**
   * Retrives the number of playertypes
   * 
   * @return - the number of available types
   */
  public int getNoOfPlayerTypes() {

    return this.playerTypes.length;
  }

  /**
   * Adds a new player type to the array
   * 
   * @param pc
   */
  public void fillInType(final PConf pc) {

    if (this.playerTypes != null) {
      if (this.filled < this.playerTypes.length) {
        this.playerTypes[this.filled] = pc;
        this.filled++;
      }
    }
    else {
      this.playerTypes = new PConf[18];
      this.playerTypes[0] = pc;
      this.filled++;
    }
  }

  /**
   * Retrieves a player type
   * 
   * @param i -
   *          the index of the type
   * @return - PConf of the type, or null, if not available for index i
   */
  public PConf getType(final int i) {

    if (this.playerTypes.length >= i - 1) {
      return this.playerTypes[i];
    }
    return null;
  }

  /**
   * retrieves all playertypes
   * 
   * @return an array containing all possible player types in PConf format!
   */
  public PConf[] getPlayerTypes() {

    return this.playerTypes;
  }

  /**
   * This method checks if all player types have been collected!
   * 
   * @return true, if the number of available playertypes is 7
   */
  public boolean playerTypesFull() {

    if (this.playerTypes == null) {
      return false;
    }
    return (this.filled == this.playerTypes.length);
  }
}
